<?php

/**
 * This is the model class for table "coincard".
 *
 * The followings are the available columns in table 'coincard':
 * @property integer $stt
 * @property string $loginName
 * @property string $loaithe
 * @property string $menhgia
 * @property string $sopin
 * @property string $CoinCardKey
 * @property integer $value
 * @property integer $used
 * @property string $time
 * @property string $tienthuc
 * @property integer $solan
 */
class Coincard extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Coincard the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'coincard';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('stt, loginName, loaithe, menhgia, sopin, CoinCardKey, value, used', 'required'),
			array('stt, value, used, solan', 'numerical', 'integerOnly'=>true),
			array('loginName', 'length', 'max'=>32),
			array('loaithe, sopin', 'length', 'max'=>100),
			array('menhgia, time, tienthuc', 'length', 'max'=>20),
			array('CoinCardKey', 'length', 'max'=>64),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('stt, loginName, loaithe, menhgia, sopin, CoinCardKey, value, used, time, tienthuc, solan', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'stt' => 'Stt',
			'loginName' => 'Login Name',
			'loaithe' => 'Loaithe',
			'menhgia' => 'Menhgia',
			'sopin' => 'Sopin',
			'CoinCardKey' => 'Coin Card Key',
			'value' => 'Value',
			'used' => 'Used',
			'time' => 'Time',
			'tienthuc' => 'Tienthuc',
			'solan' => 'Solan',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('stt',$this->stt);
		$criteria->compare('loginName',$this->loginName,true);
		$criteria->compare('loaithe',$this->loaithe,true);
		$criteria->compare('menhgia',$this->menhgia,true);
		$criteria->compare('sopin',$this->sopin,true);
		$criteria->compare('CoinCardKey',$this->CoinCardKey,true);
		$criteria->compare('value',$this->value);
		$criteria->compare('used',$this->used);
		$criteria->compare('time',$this->time,true);
		$criteria->compare('tienthuc',$this->tienthuc,true);
		$criteria->compare('solan',$this->solan);
        $criteria->order = 'time desc';

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
            'pagination'=>array(
                'pageSize'=>40,
            ),
		));
	}
}